<?php

class DB_COUNT_PV extends ORM_Table {
    static protected $table_name = 'count_pv';
    
    static public function getTableName($params = null) {
        //$table_name = self::$table_name.substr($params['article_type_id'], 0, 1);
        return self::$table_name;
    }

    static function getCount($uhash=null, $log_time) {
        $where  = "uhash ='$uhash' and log_time=$log_time";
        $rs = DAO_Finder::findOne(DB_COUNT_PV, $where,'pv');
        if(!$rs) {
            return 0;
        }else{
            return $rs->getPv();
        }
    }

    /**
     * 记录今日pv
     * @param <type> $uhash
     */
    static function writeTodayPv($uhash) {
        $where  = "uhash ='$uhash' and log_time=".date('Ymd');
        $has    = DAO_Finder::findOne(DB_COUNT_PV, $where);
        if(!$has){
            $has   = new DB_COUNT_PV();
            $has->setPv(1);
            $has->setUhash($uhash);
            $has->setLogTime(date("Ymd"));
            $has->save();
        }else{
            $has->setPv($has->getPv()+1);
            $has->save();
        }
    }
}

